package com.purebang.spaceinvaders;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 * 
 * @author kristian
 * 
 */
public class PlayerInput implements KeyListener {
	
	
	//private final String CONTROL_FILE = "data/usercontrols.txt";
	//Use int array to simulate saved file for now, they represent keycodes
	//To find key code, go to http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
	
	private int[] savedInputs = {32, 37, 39};
	private final int FIRE_BUTTON;
	private final int LEFT_BUTTON;
	private final int RIGHT_BUTTON;
	private boolean firePressed = false;
	private boolean leftPressed = false;
	private boolean rightPressed = false;
	
	
	public PlayerInput() {
		FIRE_BUTTON = savedInputs[0];
		LEFT_BUTTON = savedInputs[1];
		RIGHT_BUTTON = savedInputs[2];
	}

	@Override
	public void keyPressed(KeyEvent event) {
		int code = event.getKeyCode();
		if ( code == FIRE_BUTTON ) {
			firePressed = true;
		}
		if( code == LEFT_BUTTON ) {
			leftPressed = true;
		}
		if ( code == RIGHT_BUTTON ) {
			rightPressed = true;
		}
	}

	@Override
	public void keyReleased(KeyEvent event) {
		int code = event.getKeyCode();
		if ( code == FIRE_BUTTON ) {
			firePressed = false;
		}
		if( code == LEFT_BUTTON ) {
			leftPressed = false;
		}
		if ( code == RIGHT_BUTTON ) {
			rightPressed = false;
		}
	}
	
	

	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public boolean isFirePressed() {
		return firePressed;
	}

	public boolean isLeftPressed() {
		return leftPressed;
	}

	public boolean isRightPressed() {
		return rightPressed;
	}

}
